const install = Vue => {
	Vue.prototype.getSelfInfo = async function (flag = false) {
		let that = this;
		let {
			code,
			data
		} = await that.$application_api.getSelfInfo({}, flag);
		if (code != 0) return {};
		uni.setStorageSync('selfInfo', data);
		if (data.province_id) {
			await that.getProvinceDetail(data.province_id)
		}
		return data;
	}

	Vue.prototype.getTipsInfo = async function () {
		let that = this;
		let num = await that.getNoticeCount();
		num = num > 99 ? '99+' : num;
		let arr = [
			{
				key: 'personal',
				tips: num
			}
		];
		this.$store.commit('changeNoticeNum', arr);
	}
	Vue.prototype.getNoticeCount = async function () {
		let that = this;
		let {
			code,
			data
		} = await that.$application_api.getNoticeCount({}, false);
		if (code != 0) return 0;
		return data;
	}


	Vue.prototype.getProvinceDetail = async function (id) {
		let that = this;
		if (!id) return;
		let { code, data } = await that.$application_api.getProvinceDetail({ province_id: id }, false);
		if (code != 0) return;
		getApp().globalData.provinceInfo = Object.assign({}, { province_id: id }, data);
		uni.setStorageSync('provinceInfo', data);
		return data;
	}
}

export default install;